package com.jeeplus.modules.flowable.myListenerService.service;


import com.jeeplus.modules.flowable.myListenerService.entity.AbnormalProcessANDRepair;
import com.jeeplus.modules.flowable.myListenerService.entity.RepairTaskEntity;
import com.jeeplus.modules.flowable.myListenerService.entity.CheakAndRepair;
import com.jeeplus.modules.flowable.myListenerService.entity.MyListenter;
import com.jeeplus.modules.flowable.myListenerService.mapper.MyJianLongListenterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class MyJianLongListenterService {
    @Autowired
    MyJianLongListenterMapper myListenerMapper;

    public String[] getTableId(String id, String ProcDefId){
        MyListenter myListenter=  myListenerMapper.get(id,ProcDefId);
        String[] table = myListenter.getBusinssKey().split(":");
        return  table;
    }

    public String getAssignee(String id, String ProcDefId,String name) {
        MyListenter myListenter=  myListenerMapper.get(id,ProcDefId);
        String[] table = myListenter.getBusinssKey().split(":");
        String assignee = myListenerMapper.getTable(table[0],table[1],name);
        return assignee;
    }
    public void checkANDrepair(String id, String ProcDefId) {
        MyListenter myListenter=  myListenerMapper.get(id,ProcDefId);
        String[] table = myListenter.getBusinssKey().split(":");
        AbnormalProcessANDRepair cheakAndRepair = myListenerMapper.checkStandardAbnormal(table[1]);
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        String format = formatter.format(date);
        cheakAndRepair.setFormid(format);
        myListenerMapper.getRepairTaskDistribution(cheakAndRepair);
    }
    public void insertRepairProjectPerform(String id, String ProcDefId) {
        MyListenter myListenter=  myListenerMapper.get(id,ProcDefId);
        String[] table = myListenter.getBusinssKey().split(":");
        RepairTaskEntity repair = myListenerMapper.getRepair(table[0], table[1]);
        myListenerMapper.insertRepairProjectPerform(repair);
    }
    public void insertRepairAcceptance(String id, String ProcDefId) {
        MyListenter myListenter=  myListenerMapper.get(id,ProcDefId);
        String[] table = myListenter.getBusinssKey().split(":");
        RepairTaskEntity repair = myListenerMapper.getRepair(table[0], table[1]);
        myListenerMapper.insertRepairAcceptance(repair);
    }

}
